Introduction

In C and C++, pointers and arrays have a close relationship, and you can use pointers to access and manipulate memory in a manner similar to arrays. This is often referred to as "using pointers as arrays." Here's a brief overview:

Pointer Initialization

Pointer Arithmetic

Array Element Access

Example:

Here's a simple example demonstrating the use of a pointer as an array:

#include <stdio.h>

int main() {
    int arr[5] = {10, 20, 30, 40, 50};
    
    // Using a pointer to traverse the array
    int *ptr = arr;
    
    for (int i = 0; i < 5; ++i) {
        printf("Element %d: %d\n", i, *(ptr + i));
    }

    return 0;
}

This program uses a pointer ptr to iterate over the elements of the array arr and prints their values. The syntax *(ptr + i) is equivalent to arr[i], demonstrating how pointers can be used to access array elements.